<?php
require_once 'glob.php';
$action=$_REQUEST['action'];
switch ($action) {
	case 'singup':
		chklogin();
		$xueniao->assign('citylist',get_citylist());
		$xueniao->display('signup.htm');
		break;
	case 'chkmail':
		//获取邮件（此处以后加上随机码功能）
		$mail=$_REQUEST['mail'];
		//echo $mail;

		if($mail!==''){
			$res=$db->getrow('select * from sn_members where mail= "'.$mail.'" and isdel = "N"');
			if($res['is_mailopen']!=='Y'){
				$res1=$db->query('update sn_members set is_mailopen= "Y" where mail="'.$mail.'"');
				if($res1){
					$msg=array(
					title=>'验证成功！',
					nottitle=>'验证状态',
					cont=>'恭喜您，您的邮箱验证通过，现在您可以登陆站点。购买产品！',
					butlink=>'<a href="http://'.$siteinfo_c[url].'">点击登陆</a>',
					other=>''
					
					);
					$xueniao->display('message.htm');
				}
			}
		}
		break;
	case 'login':
		$fm_email=$_REQUEST['fm_email'];
		$fm_pass=$_REQUEST['fm_password'];
		if($fm_email!==''){
			$res=$db->getrow("select * from sn_members where mail='".$fm_email."' and isdel = 'N'");
			if($res){
				if($res['is_mailopen']=='Y'){
					if($res['password']==md5($fm_pass)){
						$_SESSION['username']=$res['name'];
						$_SESSION['mail']=$res['mail'];
						$_SESSION['memberid']=$res['id'];
						$_SESSION['tel']=$res['tel'];
						local_header('index.php?city='.$_SESSION['city']);
					}else{
						$msg=array(
						title=>'密码错误！',
						nottitle=>'验证状态',
						cont=>'对不起您的密码有误！',
						butlink=>'<a href="javascript:history.go(-1)">返回上一页</a>',
						other=>''
						
						);
						//$xueniao->display('message.htm');
					}
				}else{
					//	echo '邮箱尚未验证,验证邮箱后再试';
					$msg=array(
					title=>'邮箱未验证！',
					nottitle=>'验证状态',
					cont=>'邮箱尚未验证,验证邮箱后再试！',
					butlink=>'<a href="javascript:history.go(-1)">返回上一页</a>',
					other=>''
					
					);
					//$xueniao->display('message.htm');
				}
					
			}else{
				//echo '邮件不存在';
				$msg=array(
				title=>'邮件不存在！',
				nottitle=>'验证状态',
				cont=>'对不起，您的邮件地址不存在！',
				butlink=>'<a href="javascript:history.go(-1)">返回上一页</a>',
				other=>''
				
				);
				//$xueniao->display('message.htm');
			}
		}else{
			//echo '邮件不能为空';
			$msg=array(
			title=>'邮件不能为空！',
			nottitle=>'验证状态',
			cont=>'对不起，您的邮件地址不能為空！',
			butlink=>'<a href="javascript:history.go(-1)">返回上一页</a>',
			other=>''
			);
		}

		$xueniao->assign('msg',$msg);
		$xueniao->display('message.htm');


		break;

	case 'reg':
		$mail=$_REQUEST['fm_mail'];
		$name=$_REQUEST['fm_name'];
		$pass=$_REQUEST['fm_pass'];
		$pass2=$_REQUEST['fm_pass2'];
		$tel=$_REQUEST['fm_tel'];
		if($_REQUEST['fm_subscribe']=='Y'){
			$subscribe=$_REQUEST['fm_subscribe'];
		}else{
			$subscribe='N';
		}
		$city=$_REQUEST['fm_city'];
		if($pass!==$pass2){
			//echo '两次密码不一致';
			$msg=array(
			title=>'两次密码不一致',
			nottitle=>'验证状态',
			cont=>'对不起，您两次输入的密码不一致！',
			butlink=>'<a href="javascript:history.go(-1)">返回上一页</a>',
			other=>''
			);
			$xueniao->assign('msg',$msg);
			$xueniao->display('message.htm');

		}else{
			if($mail!==''){
				$post=array(
				name=>$name,
				mail=>$mail,
				tel=>$tel,
				password=>MD5($pass),
				subscribe=>$subscribe,
				city=>$city
				);
				$res=$db->insert('sn_members',$post);
				if($res==true){

					$sql='select * from sn_servermail where mailtype = 0';
					$resmail=$db->getrow($sql);

					$search = array ("'{name}'si",  // 名称
                                     "'{mail}'si",  // 邮件
					                 "'{chkurl}'si"  // 网址
					);
					$replace = array ($name,$mail,'http://'.$siteinfo_c[url].'/do.php?action=chkmail&mail='.$mail);

					$mailcount = preg_replace ($search, $replace, $resmail['mailcontent']);

					sendmail($resmail['smtpserver'], $resmail['smtpmail'], $resmail['smtpuser'], $resmail['smtppass'], $mail, $resmail['mailtitle'], $mailcount);

					$xueniao->assign('station','success');
					//	$xueniao->assign('email',$mail);
					//	$xueniao->assign('systemmail'.$systemmail);

					$msg=array(
					title=>'恭喜您，注册成功！',
					nottitle=>'下一步，请验证您的Email',
					cont=>'我们发送了一封验证邮件到 <STRONG>'.$mail.'</STRONG>，请到您的邮箱收信，并点击其中的链接验证您的邮箱。',
					other=>'<DIV class=help-tip>
<H3 class=help-title>收不到邮件？</H3>
<UL class=help-list>
  <LI>有可能被误判为垃圾邮件了，请到垃圾邮件文件夹找找。 </LI>
  <LI>用'.$email.' 向 '.$systemmail.' 发送一封任意内容的邮件，几分钟后即可直接登录'.$siteinfo_c[title].'。 
</LI></UL></DIV>'
);
$xueniao->assign('msg',$msg);
//此处通过邮件地址获取email登陆网址
//$emailurl='http://mail.163.com';
//$xueniao->assign('mailurl',$emailurl);

$xueniao->display('message.htm');
				}
			}else{
				//$xueniao->assign('station','error');
				//echo '名称不能为空';
				$msg=array(
				title=>'邮件不能为空',
				nottitle=>'验证状态',
				cont=>'对不起，邮件不能为空！',
				butlink=>'<a href="javascript:history.go(-1)">返回上一页</a>',
				other=>''
				);
				$xueniao->assign('msg',$msg);
				$xueniao->display('message.htm');
			}

		}
		break;

	case 'loginout':
		unset($_SESSION['username']);
		unset($_SESSION['mail']);
		unset($_SESSION['memberid']);
		local_header('do.php');
		break;
	case 'buy':
		chkunlogin();
		if($_REQUEST['goodsid']!==null &&$_REQUEST['goodsid']!==''){
			$goodsid=$_REQUEST['goodsid'];
			$sql='select * from sn_group_goods where id='.$goodsid;
		}
		$goodsinfo=$db->getrow($sql);
		$goodsinfo['tel']=$_SESSION['tel'];
		$goodsinfo['num']=1;
		//$xueniao->assign('buytitle','提交订单');
		$xueniao->assign('goodsid',$goodsid);
		$xueniao->assign('goodsinfo',$goodsinfo);
		$xueniao->display('buy.htm');
		break;
	case 'editbuy':
		chkunlogin();
		if($_REQUEST['edtid']!==null &&$_REQUEST['edtid']!==''){
			$edtid=$_REQUEST['edtid'];
			$sql='select a.num as num,a.tel as tel,b.id as goods_id ,b.name as name,b.groupprice as groupprice from sn_group_cert as a left join sn_group_goods as b on a.goods_id=b.id where a.id='.$edtid;
		}
		$goodsinfo=$db->getrow($sql);

		//$xueniao->assign('buytitle','订单信息');
		$xueniao->assign('editid',$edtid);
		$xueniao->assign('goodsid',$goodsinfo['goods_id']);
		$xueniao->assign('goodsinfo',$goodsinfo);
		$xueniao->display('buy.htm');
		break;


	case 'pay':
		chkunlogin();
		if($_REQUEST['fm_goodsid']!==null &&$_REQUEST['fm_goodsid']!==''){
			$goodsid=$_REQUEST['fm_goodsid'];
		}
		$goodsnum=$_REQUEST['fm_goodsnum'];
		$ftel=$_REQUEST['fm_tel'];
		if($goodsid!==''){
			$out_trade_no=0;
			if($_REQUEST['fm_editid']!==''&&$_REQUEST['fm_editid']!==null){
				$post=array(
				id=>$_REQUEST['fm_editid'],
				num=>$goodsnum,
				tel=>$ftel,
				);
				$res=$db->update('sn_group_cert',$post,id);
				$out_trade_no=$_REQUEST['fm_editid'];
				//	$xueniao->assign('insertid',$out_trade_no);
			}else{
				$post=array(
				goods_id=>$goodsid,
				member_id=>$_SESSION['memberid'],
				num=>$goodsnum,
				tel=>$ftel,
				is_ok=>'N'
				);
				$out_trade_no=$db->insert('sn_group_cert',$post,true);

				//	$xueniao->assign('insertid',$out_trade_no);

			}

			$xueniao->assign('insertid',$out_trade_no);
			$sql='select * from sn_group_goods where id='.$goodsid;
			$goodsinfo=$db->getrow($sql);
			$xueniao->assign('goodsinfo',$goodsinfo);

			$xueniao->assign('allprice',$goodsnum*$goodsinfo['groupprice']);
			$xueniao->assign('fnum',$goodsnum);
			$xueniao->assign('ftel',$ftel);
			$xueniao->assign('fgoodsid',$goodsid);
		}
		require_once '../../admin/inc/lib/base/cls_plugins.php';
		$PluginManager=new PluginManager('../../admin/plugins/payment');

		$alipay=$PluginManager->trigger('alipay','show',array(body=>$goodsinfo['name'],subject=>$goodsinfo['name'],out_trade_no=>$out_trade_no,total_fee=>($goodsnum*$goodsinfo['groupprice'])));
		//	$tenpay=$PluginManager->trigger('tenpay','show',array(body=>'商品描述',subject=>'测试商品',out_trade_no=>90909));

		$xueniao->assign('alipay',$alipay);
		//	$xueniao->assign('tenpay',$tenpay);

		$xueniao->assign('paybtn',$PluginManager->paybtn());
		$xueniao->display('pay.htm');
		break;
	case 'coupons':
		chkunlogin();
		$sql="select a.id as id,(a.over_time > '".date('Y-m-d')."') as isover,a.is_use as isuse,a.serial as serial,a.num as num,b.name as gname from sn_group_sens as a left join sn_group_goods as b on a.goods_id=b.id  where member_id = ".$_SESSION['memberid'];
		if($_REQUEST['certid']!=="" && $_REQUEST['certid']!==null){
			$sql.=" and a.cert_id =".$_REQUEST['certid'];
		}else {
			if($_REQUEST['stat']!=""&&$_REQUEST['stat']!==null){
				if($_REQUEST['stat']=="unuse"){
					//未使用的团购卷
					$sql.=" and a.is_use = 'N'";
				}else if($_REQUEST['stat']=="use"){
					//使用的团购卷
					$sql.=" and a.is_use = 'Y'";
				}else if($_REQUEST['stat']=="over"){
					//过期的团购卷
				 $sql.=" and a.over_time < '".date('Y-m-d')."'";
				}else if($_REQUEST['stat']=="unover"){
					//三天内过期的团购卷
					$sql.=" and DATEDIFF(a.over_time,'".date('Y-m-d')."') < '3'";

				}
			}
		}

		$senslist=$db->getlist($sql);
		$xueniao->assign('senslist',$senslist);
		$xueniao->display('uc_coupons.htm');
		break;
	case 'orders':
		chkunlogin();
		if($_REQUEST['pay']=="" || $_REQUEST['pay']=="ALL"){
			$sql="select a.id as id,b.id as bid,a.isdel as del,b.name as name,a.num as num,(a.num*b.groupprice) as price,a.is_ok as isok,b.smallimg as smallimg from sn_group_cert as a left join sn_group_goods as b on b.id=a.goods_id and a.member_id = ".$_SESSION['memberid']." order by a.id asc";
		}else{
			$sql="select a.id as id,b.id as bid,a.isdel as del,b.name as name,a.num as num,(a.num*b.groupprice) as price,a.is_ok as isok,b.smallimg as smallimg from sn_group_cert as a left join sn_group_goods as b on b.id=a.goods_id and a.member_id = ".$_SESSION['memberid']." where a.is_ok = '".$_REQUEST['pay']."'  order by a.id asc";
		}
		$orderlist=$db->getlist($sql);
		$xueniao->assign('orderlist',$orderlist);
		$xueniao->display('uc_orders.htm');
		break;
	case 'unorder':
		chkunlogin();
		$res=$db->query('update sn_group_cert set isdel = "Y" where id = '.$_REQUEST['id']);
		if($res){
			$msg=array(
			title=>'取消您的订单',
			nottitle=>'消息',
			cont=>'您的订单已取消，如需继续购买请重新选择！',
			butlink=>'<a href="javascript:history.go(-1)">返回上一页</a>',
			other=>''
			);
		}

		$xueniao->assign('msg',$msg);
		$xueniao->display('message.htm');
		break;
	case 'points':
		chkunlogin();
		$sql="select integral from sn_members where id= ".$_SESSION['memberid'];
		$userinfo=$db->getrow($sql);
		$xueniao->assign('userinfo',$userinfo);
		$xueniao->display('uc_points.htm');
		break;
	case 'credit':
		chkunlogin();
		$sql="select * from sn_members where name= '".$_SESSION['username']."'";
		$userinfo=$db->getrow($sql);
		$xueniao->assign('userinfo',$userinfo);
		$xueniao->display('uc_credit.htm');
		break;

		//***********************密码修改部分**********************************************/
	case 'settings':
		chkunlogin();
		$sql="select * from sn_members where name= '".$_SESSION['username']."'";
		$userinfo=$db->getrow($sql);
		$xueniao->assign('userinfo',$userinfo);
		$xueniao->display('uc_settings.htm');
		break;

	case 'updateuerinfo':
		chkunlogin();
		$mobile=$_REQUEST['mobile'];
		if($_REQUEST['password']==$_REQUEST['password2']){
			if($_REQUEST['password']!=="" ){
				$password=$_REQUEST['password'];
				$sql='update sn_members set password = "'.md5($password).'",tel= "'.$mobile.'" where mail = "'.$_REQUEST['mail'].'"';
			}else{
				$sql='update sn_members set tel= "'.$mobile.'" where mail = "'.$_REQUEST['mail'].'"';
			}
			$res=$db->query($sql);
			if($res){
				local_header('do.php?action=settings');
			}
		}else{
			$msg=array(
			title=>'两次输入的密码不一致',
			nottitle=>'验证状态',
			cont=>'对不起，两次输入的密码不一致！',
			butlink=>'<a href="javascript:history.go(-1)">返回上一页</a>',
			other=>''
			);
			$xueniao->assign('msg',$msg);
			$xueniao->display('message.htm');
		}
		break;
		//************************密码修改部分*********************************************/

	case 'invites':
		$xueniao->display('uc_invites.htm');
		break;

	case'sendmsg':
		chkunlogin();
		$sql="select * from sn_group_sens where id=".$_REQUEST['id'];
		$res=$db->getrow($sql);
		if($res){

			require_once '../../admin/inc/lib/base/cls_plugins.php';
			$PluginManager=new PluginManager('../../admin/plugins/serverSMS');
			$sendmsg=$PluginManager->trigger('localservice','send',array(mobile=>$res['mobile'],msg=>'您的编号为：'.$res['serial'].'的团购卷，密码为：'.$res['pass'].',对应'.$res['num'].'件商品。请您在消费时出示该条信息！'));
			//echo $sendmsg;
			if($sendmsg=="success"){
				$msg=array(
				title=>'短信发送成功',
				nottitle=>'短信发送',
				cont=>'恭喜您，您的优惠卷信息已成功发送至您的手机！',
				butlink=>'<a href="javascript:history.go(-1)">返回上一页</a>',
				other=>''
				);
			}else{
				$msg=array(
				title=>'短信发送失败',
				nottitle=>'短信发送',
				cont=>'对不起，短信发送失败。您可以选择打印方式获取优惠券或稍后再尝试短信获取！',
				butlink=>'<a href="javascript:history.go(-1)">返回上一页</a>',
				other=>''
				);
			}

		}
		$xueniao->assign('msg',$msg);
		$xueniao->display('message.htm');
		break;

	case "print":
		chkunlogin();
		$sql="select a.id as id,a.over_time as overtime, a.pass as pass,a.serial as serial,a.num as num,b.name as gname from sn_group_sens as a left join sn_group_goods as b on a.goods_id=b.id  where member_id = ".$_SESSION['memberid']." and a.id=".$_REQUEST['id'];
		$coupon=$db->getrow($sql);
		$xueniao->assign('coupon',$coupon);


		$xueniao->assign('barcode','../../admin/inc/lib/base/lib_barcode.php?code='.$coupon['serial']);
		$xueniao->display('print.htm');
		break;

		/*********************************账户充值*************************/
	case 'docredit':
		chkunlogin();
		$payinfo=array(name=>'账户充值',num=>100,price=>100);
		$xueniao->assign('payinfo',$payinfo);
		$xueniao->display('credit.htm');
		break;
	case 'dopay':
		chkunlogin();
		$xueniao->assign('allprice',$_REQUEST['fm_paynum']);
		require_once '../../admin/inc/lib/base/cls_plugins.php';
		$PluginManager=new PluginManager('../../admin/plugins/payment');
		$pay_sen_id=randomkeys(11);
		$alipay=$PluginManager->trigger('alipay','show',array(body=>"比奇账户充值",subject=>"账户充值",out_trade_no=>$pay_sen_id,total_fee=>$_REQUEST['fm_paynum']));
		//	$tenpay=$PluginManager->trigger('tenpay','show',array(body=>'商品描述',subject=>'测试商品',out_trade_no=>90909));
		$xueniao->assign('alipay',$alipay);
		//	$xueniao->assign('tenpay',$tenpay);

		$xueniao->assign('paybtn',$PluginManager->paybtn());
		$xueniao->display('dopay.htm');
		break;
		/*********************************账户充值*************************/
	case 'subc':
		$xueniao->assign('citylist',get_citylist('','','name'));
		$xueniao->display('subc.htm');
		break;
	case 'subinfo':
		$xueniao->assign('citylist',get_citylist('其他','','name'));
		$xueniao->display('subinfo.htm');
		break;
	case 'subbizinfo':
		if($_REQUEST['fm_name']!==''){
			$post=array(
			name=>$_REQUEST['fm_name'],
			tel=>$_REQUEST['fm_tel'],
			othercontact=>$_REQUEST['fm_othercontact'],
			city=>$_REQUEST['fm_city'],
			bizname=>$_REQUEST['fm_bizname'],
			content=>$_REQUEST['fm_content']
			);

			$res=$db->insert('sn_gruop_subgroup',$post);
			if($res){

				$msg=array(
				title=>'提供团购信息',
				nottitle=>'系统提示',
				cont=>'恭喜你，提交成功！',
				butlink=>'<a href="javascript:history.go(-1)">返回上一页</a>',
				other=>''
				);
			}else{
				$msg=array(
				title=>'提供团购信息',
				nottitle=>'系统提示',
				cont=>'对不起，提交失败,请稍后再试.',
				butlink=>'<a href="javascript:history.go(-1)">返回上一页</a>',
				other=>''
				);
			}
		}else {
			$msg=array(
			title=>'提供团购信息',
			nottitle=>'系统提示',
			cont=>'对不起，您的电话不能为空.',
			butlink=>'<a href="javascript:history.go(-1)">返回上一页</a>',
			other=>''
			);
		}

		$xueniao->assign('msg',$msg);
		$xueniao->display('message.htm');
		break;

		/*************************************商家管理界面**************************/

		//登录后台部分
	case 'mlogin':
		$xueniao->display('mlogin.htm');
		break;
	case 'min':
		$fm_menchant=$_REQUEST['fm_menchant'];
		$fm_pass=$_REQUEST['fm_password'];
		if($fm_menchant!==''){
			$res=$db->getrow("select * from sn_group_menchant where name='".$fm_menchant."' and isdel = 'N'");
			if($res){
				//暂时不做MD5加密
				if($res['password']==$fm_pass){
					$_SESSION['menchant']=$res['name'];
					$_SESSION['mail']=$res['mail'];
					$_SESSION['memberid']=$res['id'];
					$_SESSION['tel']=$res['tel'];
					local_header('do.php?action=mcenter');
				}else{
					$msg=array(
					title=>'密码错误！',
					nottitle=>'验证状态',
					cont=>'对不起您的密码有误！',
					butlink=>'<a href="javascript:history.go(-1)">返回上一页</a>',
					other=>''
						
					);
					$xueniao->assign('msg',$msg);
					$xueniao->display('message.htm');
				}

			}else{

				$msg=array(
				title=>'商家名称错误！',
				nottitle=>'验证状态',
				cont=>'商家名称错误！',
				butlink=>'<a href="javascript:history.go(-1)">返回上一页</a>',
				other=>''
				);
				$xueniao->assign('msg',$msg);
				$xueniao->display('message.htm');
			}


		}else{

			$msg=array(
			title=>'商家名称错误！',
			nottitle=>'验证状态',
			cont=>'商家名称不能为空！',
			butlink=>'<a href="javascript:history.go(-1)">返回上一页</a>',
			other=>''
			);
			$xueniao->assign('msg',$msg);
			$xueniao->display('message.htm');
		}

		break;

		//验证团购券部分
	case 'mcenter':
		//	unset($_SESSION['memberid']);
		chkmenc();
		$xueniao->display('chkcoupon.htm');
		break;
	case 'chkcp':
		chkmenc();
		$fm_cpname=$_REQUEST['fm_cpname'];
		$fm_pass=$_REQUEST['fm_password'];
		if($fm_cpname!==''){
			$res=$db->getrow("select * from sn_group_sens where serial='".$fm_cpname."'");

			$res1=$db->getrow("select merchant_id from sn_group_goods where id=".$res['goods_id']);

			if($res1['merchant_id']!==$_SESSION['memberid']){
				$msg=array(
				title=>'操作有误！',
				nottitle=>'操作状态',
				cont=>'该团购卷不是本商家！',
				butlink=>'<a href="do.php?action=mcenter">返回验证通道</a>',
				other=>''
				);
				$xueniao->assign('msg',$msg);
				$xueniao->display('message.htm');
					
			}else {
				if($res){
					//暂时不做MD5加密
					if($res['pass']==$fm_pass){
						//过期验证
						if($res['over_time ']>= date('Y-m-d')){
							$msg=array(
							title=>'验证失败！',
							nottitle=>'验证状态',
							cont=>'该团购券已过期！<br/>过期时间为'.$res['over_time'].'！',
							butlink=>'<a href="do.php?action=mcenter">返回验证通道</a>',
							other=>''
							);
						}else{
							if($res['is_use']=="N"){
								$msg=array(
								title=>'验证成功！',
								nottitle=>'验证状态',
								cont=>'恭喜：该团购券尚未使用完毕。还可购买'.($res['num']-$res['use_num']).'件商品！<br/>过期时间为'.$res['over_time'].'！',
								butlink=>'<br/><form method="get" action="">使用数量: <input type="text" class="f-input"  size="10" name="fm_num" id="fm_num"  value="'.($res['num']-$res['use_num']).'"/>
						<input tabindex="4" type="submit" value="开始使用" name="commit" id="login-submit" class="formbutton"/>
						<input type="hidden" name="cpid" value="'.$res['id'].'" />  
						<input type="hidden" name="action" value="usecp" />  
						</form><br/><br/>',
								//butlink=>'<a href="do.php?action=usecp&cpid='.$res['id'].'">点击此处，开始使用</a><br/><br/><br/>',
								other=>'<a href="do.php?action=mcenter">返回验证通道</a>'
								);
							}else{
								//echo $_SESSION['memberid'];
								$msg=array(
								title=>'验证失败！',
								nottitle=>'验证状态',
								cont=>'该团购券已使用完毕！<br/>上次使用时间为'.$res['use_time'].'！',
								butlink=>'<a href="do.php?action=mcenter">返回验证通道</a>',
								other=>''
								);

							}
						}
						$xueniao->assign('msg',$msg);
						$xueniao->display('message.htm');
					}else{
						$msg=array(
						title=>'密码错误！',
						nottitle=>'验证状态',
						cont=>'对不起您的团购卷密码有误！',
						butlink=>'<a href="do.php?action=mcenter">返回验证通道</a>',
						other=>''
						);
						$xueniao->assign('msg',$msg);
						$xueniao->display('message.htm');
					}

				}else{
					$msg=array(
					title=>'团购卷编号不存在！',
					nottitle=>'验证状态',
					cont=>'对不起您的团购卷编号有误，检查后再试！',
					butlink=>'<a href="do.php?action=mcenter">返回验证通道</a>',
					other=>''
					);
					$xueniao->assign('msg',$msg);
					$xueniao->display('message.htm');

				}
			}
			}else{

				$msg=array(
				title=>'团购卷编号为空！',
				nottitle=>'验证状态',
				cont=>'团购卷编号不能为空！',
				butlink=>'<a href="do.php?action=mcenter">返回验证通道</a>',
				other=>''
				);
				$xueniao->assign('msg',$msg);
				$xueniao->display('message.htm');
			}
		
			break;

			case 'usecp':
				chkmenc();
				$cpid=$_REQUEST['cpid'];
				$usenum=$_REQUEST['fm_num'];
				$res=$db->getrow("select * from sn_group_sens where id='".$cpid."'");
				if($res){
					if(($usenum+$res['use_num'])>$res['num']){
						$msg=array(
						title=>'操作有误！',
						nottitle=>'操作状态',
						cont=>'团购卷使用欲数量，大于可用数量！',
						butlink=>'<a href="do.php?action=mcenter">返回验证通道</a>',
						other=>''
						);
						$xueniao->assign('msg',$msg);
						$xueniao->display('message.htm');
							
					}else{
						if(($usenum+$res['use_num'])==$res['num']){
							$res=$db->query("update sn_group_sens set use_num=".($usenum+$res['use_num']).",use_time='".date('Y-m-d')."',is_use='Y' where id='".$cpid."'");
							if($res){
								$msg=array(
								title=>'操作成功！',
								nottitle=>'操作状态',
								cont=>'团购卷今天将正式使用完毕！',
								butlink=>'<a href="do.php?action=mcenter">返回验证通道</a>',
								other=>''
								);
								$xueniao->assign('msg',$msg);
								$xueniao->display('message.htm');
							}
						}else{
							$res=$db->query("update sn_group_sens set use_num=".($usenum+$res['use_num']).",use_time='".date('Y-m-d')."' where id='".$cpid."'");
							if($res){
								$msg=array(
								title=>'操作成功！',
								nottitle=>'操作状态',
								cont=>'团购卷已完成本次消费记录！',
								butlink=>'<a href="do.php?action=mcenter">返回验证通道</a>',
								other=>''
								);
								$xueniao->assign('msg',$msg);
								$xueniao->display('message.htm');
							}

						}

					}
				}

				break;

				/*************************************商家管理界面**************************/

			default:
				chklogin();
				$xueniao->display('login.htm');
				break;
		}
		?>